<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>

    <script src="../utils/js/old_version/react.development.js"></script>
    <script src="../utils/js/old_version/react-dom.development.js"></script>
    <script src="../utils/js/old_version/babel.min.js"></script>
    <script src="../utils/js/old_version/prop-types.js"></script>

    <script type="text/babel">
      class Animation extends React.Component {
        state = {
          opacity: 1,
        };
        timeId = null;
        remove = () => {
          ReactDOM.unmountComponentAtNode(document.getElementById("app"));
        };
        render() {
          return (
            <div>
              <h1 style={{ opacity: `${this.state.opacity}` }}>
                React 渐渐消失
              </h1>
              <button onClick={this.remove}>移除组件</button>
            </div>
          );
        }

        componentDidMount() {
          this.timeId = setInterval(() => {
            let { opacity } = this.state;
            opacity -= 0.1;
            if (opacity <= 0) opacity = 1;
            this.setState({ opacity });
          }, 200);
        }

        componentWillUnmount() {
          this.timeId && clearInterval(this.timeId);
        }
      }
      ReactDOM.render(<Animation />, document.getElementById("app"));
    </script>
  </body>
</html>
